package projectOne.taoCan;

import projectOne.MobileCard;
import projectOne.ServicePackage;
import projectOne.service.CallService;
import projectOne.service.NetService;
import projectOne.service.SendService;

public class NetHead extends ServicePackage implements CallService, SendService, NetService {
    private int talkTime;
    private int smsCount;
    private int flow;

    public NetHead() {
        super(68);
        this.talkTime = 0;
        this.smsCount =0;
        this.flow =10*1024;
    }


    @Override
    public String toString() {
        return "通话时长："+talkTime+"\n短信条数："+smsCount+"\n流量："+flow/1024+"G"+"\n资费："+super.getPrice();
    }

    @Override
    public void call(int time, MobileCard card) {
        card.setRealTalkTime(card.getRealTalkTime()+time);
        card.setMoney(card.getMoney()-0.5*time);
        card.setConsumAmount(card.getConsumAmount()+0.5*time);
    }

    @Override
    public void net(int flow, MobileCard card) {
        int temp=1;
        while (temp++<=flow){
            if (this.flow-card.getRealFlow()>=1){
                card.setRealFlow(card.getRealFlow()+1);
            } else {
                card.setRealFlow(card.getRealFlow()+1);
                card.setMoney(card.getMoney()-0.5);
                card.setConsumAmount(card.getConsumAmount()+0.5);
            }
        }
    }

    @Override
    public void send(int count, MobileCard card) {
        card.setRealSMSCount(card.getRealSMSCount()+count);
        card.setMoney(card.getMoney()-0.2*count);
        card.setConsumAmount(card.getConsumAmount()+0.2*count);
    }

    public int getTalkTime() {
        return talkTime;
    }

    public void setTalkTime(int talkTime) {
        this.talkTime = talkTime;
    }

    public int getSmsCount() {
        return smsCount;
    }

    public void setSmsCount(int smsCount) {
        this.smsCount = smsCount;
    }

    public int getFlow() {
        return flow;
    }

    public void setFlow(int flow) {
        this.flow = flow;
    }
}
